/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* E.P. Scene Graph
* Developed by:
*       - Eduardo Ribeiro (eribeiro @ tecgraf . puc-rio . br)
*       - Peter Dam (peter @ tecgraf . puc-rio . br)
* File: Vec2.h
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#ifndef _EPSG_VEC2_
#define _EPSG_VEC2_

#include <math.h>

namespace EPSG
{
	template <typename T>
	class Vec2
	{
	public:
		/* [CONSTRUCTOR] */	Vec2();
		/* [CONSTRUCTOR] */	Vec2( T x, T y );

		EPSG::Vec2<T>		operator+( const Vec2& rhs );
		EPSG::Vec2<T>&		operator+=( const Vec2& rhs );
		EPSG::Vec2<T>		operator-( const Vec2& rhs );
		EPSG::Vec2<T>&		operator-=( const Vec2& rhs );
		EPSG::Vec2<T>		operator*( const Vec2& rhs );
		EPSG::Vec2<T>&		operator*=( const Vec2& rhs );
		void				operator=( const Vec2& rhs );
		T&					operator[]( int index );

		void				setValues( T x, T y );

		T					x, y;
	};
}

/* TEMPLATE METHODS */
template <typename T>
EPSG::Vec2<T>::Vec2() : x( 0 ), y( 0 )
{

}

template <typename T>
EPSG::Vec2<T>::Vec2( T x, T y )
{
	this->x = x;
	this->y = y;
}

/* OPERATORS */
template <typename T>
EPSG::Vec2<T> EPSG::Vec2<T>::operator+( const Vec2& rhs )
{
	EPSG::Vec2<T> ret;
	ret = *this;
	ret += rhs;
	return ret;
}

template <typename T>
EPSG::Vec2<T>& EPSG::Vec2<T>::operator+=( const Vec2& rhs )
{
	x += rhs.x;
	y += rhs.y;

	return *this;
}

template <typename T>
EPSG::Vec2<T> EPSG::Vec2<T>::operator-( const Vec2& rhs )
{
	EPSG::Vec2<T> ret;
	ret = *this;
	ret -= rhs;
	return ret;
}

template <typename T>
EPSG::Vec2<T>& EPSG::Vec2<T>::operator-=( const Vec2& rhs )
{
	x -= rhs.x;
	y -= rhs.y;

	return *this;
}

template <typename T>
EPSG::Vec2<T> EPSG::Vec2<T>::operator*( const Vec2& rhs )
{
	EPSG::Vec2<T> ret;
	ret = *this;
	ret *= rhs;
	return ret;
}

template <typename T>
EPSG::Vec2<T>& EPSG::Vec2<T>::operator*=( const Vec2& rhs )
{
	x *= rhs.x;
	y *= rhs.y;

	return *this;
}

template <typename T>
void EPSG::Vec2<T>::operator=( const Vec2& rhs )
{
	x = rhs.x;
	y = rhs.y;
}

template <typename T>
T& EPSG::Vec2<T>::operator[]( int index )
{
	switch( index )
	{
	case 0:
		return x;
	case 1:
		return y;
	default:
		return NULL;
	}
}

template <typename T>
void EPSG::Vec2<T>::setValues( T x, T y )
{
	this->x = x;
	this->y = y;
}

#endif //_EPSG_VEC2_